package cn.admobiletop.adsuyi.adapter.gdt.data;

import android.app.Activity;
import android.os.SystemClock;

import com.qq.e.ads.rewardvideo.RewardVideoAD;

import cn.admobiletop.adsuyi.ad.data.ADSuyiRewardVodAdInfo;
import cn.admobiletop.adsuyi.ad.listener.ADSuyiRewardVodAdListener;

/**
 * @author ciba
 * @description 激励视频广告内容对象
 *              需要继承 BaseAdInfo<ADSuyiRewardVodAdListener, E>，其中E为渠道的激励视频广告对象，并实现 ADSuyiRewardVodAdInfo 接口
 * @date 2020/4/7
 */
public class RewardVodAdInfo extends BaseAdInfo<ADSuyiRewardVodAdListener, RewardVideoAD> implements ADSuyiRewardVodAdInfo {
    private static final long DELTA_TIME = 1000;

    public RewardVodAdInfo(String platformPosId) {
        super(platformPosId);
    }

    @Override
    public void showRewardVod(Activity activity) {
        if (activity != null
                && !isReleased()
                && isReady()
                && getAdapterAdInfo() != null
                && !hasShown()
                && !hasExpired()) {
            // 以下为调用广点通展示激励广告的方法
            getAdapterAdInfo().showAD();
        }
    }

    /**
     * 广告是否使用过
     * @return
     */
    @Override
    public boolean hasShown() {
        return getAdapterAdInfo() == null || getAdapterAdInfo().hasShown();
    }

    /**
     * 广告是否过期
     * @return
     */
    @Override
    public boolean hasExpired() {
        return getAdapterAdInfo() == null || SystemClock.elapsedRealtime() >= (getAdapterAdInfo().getExpireTimestamp() - DELTA_TIME);
    }

    /**
     * 广告是否可播放
     * @return
     */
    @Override
    public boolean isReady() {
        return true;
    }

    /**
     * 广告释放
     */
    @Override
    public void releaseAdapter() {
        super.releaseAdapter();
        setAdapterAdInfo(null);
    }
}
